﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Eg.Core;

namespace NhConfig
{
    public class ProductShow
    {
        public static void Show(string headering,IEnumerable<Movie> movies)
        {
            Console.WriteLine(headering);
            foreach (var m in movies)
                ShowMovie(m);
            Console.WriteLine();
        }

        public static void Show(string heading,Book book)
        {
            Console.WriteLine(heading);
            ShowBook(book);
            Console.WriteLine();
        }

        public static void Show(string headering,IEnumerable<Product> products)
        {
            Console.WriteLine(headering);
            foreach (var p in products)
            {
                if (p is Movie)
                {
                    ShowMovie((Movie)p);
                }
                if (p is Book)
                {
                    ShowBook((Book)p);
                }
                else
                    ShowProduct(p);
            }
        }

        public static void Show(string headering,decimal moneyValue)
        {
            Console.WriteLine(headering);
            Console.WriteLine("{0:c}", moneyValue);
            Console.WriteLine();
        }

        public static void Show(string headering,IEnumerable<NameAndPrice> results)
        {
            Console.WriteLine(headering);
            foreach (var item in results)
                ShowNameAndPrice(item);
            Console.WriteLine();
        }

        public static void ShowNameAndPrice(NameAndPrice item)
        {
            Console.WriteLine("{0:c} {1}",item.Price,item.Name);
        }

        public static void ShowProduct(Product p)
        {
            Console.WriteLine("{0:c} {1}", p.UnitPrice, p.Name);
        }

        public static void ShowBook(Book b)
        {
            Console.WriteLine("{0:c} {1} (ISBN {2})", b.UnitPrice, b.Name, b.ISBN);
        }

        public static void ShowMovie(Movie m)
        {
            //Console.WriteLine("")
            var star = m.Actors.Select(u => u.Actor).FirstOrDefault();
            Console.WriteLine("{0:c} {1} starring {2}", m.UnitPrice, m.Name, star ?? "nobody");

        }
    }
}
